package io.xxx.xbutler.core.callback;

import com.alibaba.fastjson2.JSONObject;
import io.xxx.xbutler.domain.Callback;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

import java.time.LocalDateTime;

/**
 * 通过好友请求回调接口（兼容PC）
 * <p>
 * 回调条件：
 * 1、微信用户添加机器人好友
 * 2、机器人关闭了自动通过好友请求（不会自动通过好友验证）
 * 3、机器人与微信用户双边都不是好友关系。
 *
 * <pre>
 * {
 *     "vcMerchantNo": "202309130012311",
 *     "vcRobotWxId": "wxid_lloyzecs12kd22",
 *     "vcRobotSerialNo": "8448826AA1B6C1CDABE6B8D9551F7F9A",
 *     "vcSerialNo": "20250113171947113295518266184",
 *     "nType": 3011,
 *     "nResult": 1,
 *     "vcResult": "SUCCESS",
 *     "nTimeStamp": 1736760017286,
 *     "Data": {
 *         "Code": "1",
 *         "vcFriendWxId": "wxid_gh28eq3lixoq22",
 *         "vcFriendSerialNo": "F9B130C002499CB2A19B99F8544F3D7D",
 *         "vcWxAlias": "xiaoao0320",
 *         "vcNickName": "快乐相随",
 *         "vcBase64NickName": "5b+r5LmQ55u46ZqP",
 *         "vcHeadImages": null,
 *         "nSex": 0,
 *         "vcCountry": null,
 *         "vcProvince": "Hunan",
 *         "vcCity": "Changsha",
 *         "vcLanguage": "CN",
 *         "vcContent": null,
 *         "vcChatRoomId": "",
 *         "vcChatRoomSerialNo": "",
 *         "nScene": 0,
 *         "vcSourceChatRoomId": "",
 *         "vcSourceNickName": "",
 *         "vcSourceUserName": ""
 *     }
 * }
 * </pre>
 */
@Slf4j
@Component
public class _3011Handler extends RobotContactHandler implements CallbackHandler {

    @Override
    public String name() {
        return "通过好友请求回调";
    }

    @Override
    public boolean supports(int type) {
        return type == 3011;
    }

    @Override
    public void handle(Callback callback) {
        LocalDateTime now = LocalDateTime.now();
        saveRobotContact(callback, (JSONObject) callback.getData(), now);
    }
}
